package com.ifast.job.jobs;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.ifast.oupei.domain.MatchDO;
import com.ifast.oupei.domain.OddsDO;
import com.ifast.oupei.service.CompanyService;
import com.ifast.oupei.service.MatchService;
import com.ifast.oupei.service.OddsService;
import com.ifast.oupei.util.HTMLParserUtil;

@Component
public class GetOddsJob implements Job {
	@Autowired
	MatchService matchService;
	@Autowired
	CompanyService companyService;
	@Autowired
	OddsService oddsService;
	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		//获取目前没有赔率的比赛赔率
		List<Integer> list = companyService.getTeamIdArray();
		List<MatchDO> matchList = matchService.getNoOddsList();
		//对赔率进行插入处理
		for (MatchDO matchDO : matchList) {
			List<OddsDO> oddsVOList = new ArrayList<OddsDO>();
			try {
				oddsVOList = HTMLParserUtil.getOddsList(matchDO.getId(), matchDO.getTicketsId(),list);
				for (OddsDO oddsDO : oddsVOList) {
					//oddsDO.setCompanyName(null);
					List<OddsDO> lists = oddsService.selectOddsList(oddsDO.getMatchId(), oddsDO.getCompanyId());
					if(lists.size()==0)oddsService.insert(oddsDO);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		List<OddsDO> oddsList= oddsService.deleteOddsList();
		for (OddsDO oddsDO : oddsList) {
			oddsService.deleteById(oddsDO.getId());
		}
	}
}
